﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Evaluant.NLinq.Expressions
{
    public class ClauseList : Expression, IList<QueryBodyClause>
    {
        public ClauseList()
        {
            innerList = new List<QueryBodyClause>();
        }

        public ClauseList(IEnumerable<QueryBodyClause> enumerable)
        {
            innerList = new List<QueryBodyClause>(enumerable);
        }

        private IList<QueryBodyClause> innerList;

        #region IList<QueryBodyClause> Members

        public int IndexOf(QueryBodyClause item)
        {
            return innerList.IndexOf(item);
        }

        public void Insert(int index, QueryBodyClause item)
        {
            innerList.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            innerList.RemoveAt(index);
        }

        public QueryBodyClause this[int index]
        {
            get
            {
                return innerList[index];
            }
            set
            {
                innerList[index] = value;
            }
        }

        #endregion

        #region ICollection<QueryBodyClause> Members

        public void Add(QueryBodyClause item)
        {
            this.innerList.Add(item);
        }

        public void Clear()
        {
            innerList.Clear();
        }

        public bool Contains(QueryBodyClause item)
        {
            return innerList.Contains(item);
        }

        public void CopyTo(QueryBodyClause[] array, int arrayIndex)
        {
            innerList.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return innerList.Count; }
        }

        public bool IsReadOnly
        {
            get { return innerList.IsReadOnly; }
        }

        public bool Remove(QueryBodyClause item)
        {
            return innerList.Remove(item);
        }

        #endregion

        #region IEnumerable<QueryBodyClause> Members

        public IEnumerator<QueryBodyClause> GetEnumerator()
        {
            return innerList.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return innerList.GetEnumerator();
        }

        #endregion


        public override void Accept(NLinqVisitor visitor)
        {
            throw new NotImplementedException();
        }

        public override ExpressionTypes ExpressionType
        {
            get { return ExpressionTypes.ClauseList; }
        }

        public QueryBodyClause[] ToArray()
        {
            return ((List<QueryBodyClause>)innerList).ToArray();
        }
    }

    public abstract class QueryBodyClause : Expression
    {
        public abstract ClauseTypes ClauseType { get; }

        public override ExpressionTypes ExpressionType
        {
            get { return ExpressionTypes.Clause; }
        }
    }
}
